﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading;
using System.Threading.Tasks;

namespace GameServer
{
    // 游戏线程基类
    public class GameThreadBase
    {
        private Thread _thread;
        private String tag;

        /// <summary>
        /// 构造函数
        /// </summary>
        /// <param name="tag">线程名</param>
        public GameThreadBase(String tag)
        {
            // 线程入口方法为Run函数
            _thread = new Thread(Run);

            this.tag = tag;
        }

        /// <summary>
        /// 启动线程
        /// </summary>
        public void Start()
        {
            _thread.Start();
        }

        /// <summary>
        /// 线程入口函数
        /// </summary>
        public virtual void Run()
        {
        }

        /// <summary>
        /// 线程结束
        /// </summary>
        public void Stop()
        {
            _thread.Join();
        }
    }
}
